package com.yuanqi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanqi.common.Result;
import com.yuanqi.pojo.Unit;
import com.yuanqi.service.UnitService;
import com.yuanqi.mapper.UnitMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author LENOVO
* @description 针对表【unit(计量单位)】的数据库操作Service实现
* @createDate 2025-08-26 15:25:04
*/
@Service
public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit>
    implements UnitService{

    @Override
    public Result<Object> getUnitPage(Integer current, Integer size, String unitName) {
        Page<Unit> page = new Page<>(current, size);
        LambdaQueryWrapper<Unit> wrapper = new LambdaQueryWrapper<>();
        
        if (StringUtils.hasText(unitName)) {
            wrapper.like(Unit::getUnitName, unitName);
        }
        
        wrapper.orderByDesc(Unit::getCreatedAt);
        Page<Unit> result = this.page(page, wrapper);
        
        return Result.success(result);
    }
}




